#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int i=1;i<=t;i++){
        int ans=0;
        int n,m,l,v;
        cin>>n>>m>>l>>v;
        int d,cars,b;
        for(int j=1;j<=n;j++){
            cin>>d>>cars>>b;
            if(cars>v)ans++;
        }
        int a;
        for(int j=1;j<=m;j++){
            cin>>a;
        }
        if(ans!=0){
            m-=1;
        }
        cout<<ans<<" "<<m<<endl;
    }
    return 0;
}